/*
 * ty_memcached.h
 *
 *  Created on: 2013. 6. 25.
 *      Author: the2
 */

#ifndef TY_MEMCACHED_H_
#define TY_MEMCACHED_H_

#include "ty_pattern.h"
#include <libmemcached/memcached.h>

#define Memcache tylenol::memcached::CMemcached::GetInstance()

namespace tylenol { namespace memcached {

class CMemcached : public pattern::CSingleton<CMemcached>
{
	friend class pattern::CSingleton<CMemcached>;
public:
	bool Init(const char *address);
	bool Release();

	memcached_return_t Set( const char *key, const char *value, const size_t size, time_t expiration );
	char* Get( const char *key, size_t *valueLen, uint32_t *flags, memcached_return_t *error );
	memcached_return_t MGet( const char* const *keys, const size_t *key_length, size_t number_of_keys );
	char* Fetch( char *return_key, size_t *return_key_length, size_t *value_length, uint32_t *flags, memcached_return_t *error );

	memcached_return_t Delete( const char *key, size_t key_length, time_t expiration );
	const char* GetErrorString( memcached_return_t rc );

	memcached_return_t FlushAll();

private:
	CMemcached():pMemc(0), pServer(0) {};
	virtual ~CMemcached() {};
	memcached_st		*pMemc;
	memcached_server_st	*pServer;
};

} /*memcached*/ } /*tylenol*/


#endif /* TY_MEMCACHED_H_ */
